package com.bytecub.simulate.device.controller;

import com.bytecub.common.domain.DataResult;
import com.bytecub.simulate.device.instance.DeviceBoot;
import com.bytecub.simulate.device.instance.DeviceInstance;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 *  * ByteCub.cn.
 *  * Copyright (c) 2020-2021 All Rights Reserved.
 *  * 
 *  * @author bytecub@163.com songbin
 *  * @version Id: TestController.java, v 0.1 2021-01-07  Exp $$
 *  
 */
@RestController
@RequestMapping("simulate")
@Slf4j
public class TestController {
    @Autowired
    DeviceBoot deviceBoot;

    /** 获取指定协议属性 */
    @RequestMapping(value = "test", method = RequestMethod.POST)
    public DataResult queryByDev(String index, String devCode) {
        try {
            return DataResult.ok();
        } catch (Exception e) {
            log.warn("", e);
            return DataResult.fail("异常");
        }
    }

    /** 获取指定协议属性 */
    @RequestMapping(value = "report", method = RequestMethod.POST)
    public DataResult report() {
        try {
            DeviceInstance deviceInstance = deviceBoot.getDeviceList().get(0);
            deviceInstance.reportData();
            return DataResult.ok();
        } catch (Exception e) {
            log.warn("", e);
            return DataResult.fail("异常");
        }
    }
}
